package genericdemo;
class MyArray<T> {
    //public T[] obj = new T[3];
    public T[] obj = (T[])new Object[3];

    public T getPos(int pos) {
        return obj[pos];
    }
    public void setObj(int pos, T val) {
        obj[pos] = val;
    }
}
public class Test {
    public static void main(String[] args) {
        //实例化对象的同时，指定当前泛型类 的指定参数类型是Integer
        //指定的参数类型，必须是引用类型
        MyArray<Integer> myArray = new MyArray<Integer>();
        //就可以存储 指定的数据类型
        myArray.setObj(0,10);
        myArray.setObj(1,45);
        myArray.setObj(2,44);
        int d = myArray.getPos(2);

        System.out.println("===========");
        MyArray<String> myArray2 = new MyArray<>();
        myArray2.setObj(0,"hello");
        myArray2.setObj(1,"world");

        String str = myArray2.getPos(0);
    }
}
